package cn.cloud9.intf;

import cn.cloud9.po.User;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * @author OnCloud9
 * @description
 * @project Springboot-CXF
 * @date 2022年04月23日 16:53
 */
@Service("userService")
public class UserServiceImpl implements UserService{
    List<User> userList;

    public UserServiceImpl() {
        userList = new ArrayList<>();
        for (int i = 1; i < 11; i++) {
            User user = new User();
            user.setCode(1000 + i);
            user.setName("user - " + user.getCode());
            user.setPassword("123456");
            userList.add(user);
        }
    }

    @Override
    public boolean saveUser(User user) {
        return null != user;
    }

    @Override
    public boolean deleteUser(Integer id) {
        return null != id;
    }

    @Override
    public boolean updateUser(User user) {
        return null != user;
    }

    @Override
    public List<User> listUsers() {
        return userList;
    }

    @Override
    public User findUserById( Integer code) {
        return userList.stream().filter(user -> user.getCode().equals(code)).findFirst().get();
    }
}
